<?php
/**
 * Kontroller RestrictedKeyword
 *
 */
class RestrictedKeywordController extends Controller {
	/**
	 * Strona glowna
	 *
	 */
	public function IndexAction() {

		//-----Zapis---------------------------------------------------------------------------------------
		if (isset($_POST['zapisz']) ) {
						
			$idRestrictedKeyword = $_REQUEST['id_wp_restricted_keyword'];
			$idRestrictedKeyword = $idRestrictedKeyword=="" ? "-1" : $idRestrictedKeyword;

			$objRestrictedKeyword = new RestrictedKeyword($idRestrictedKeyword, $_POST['keyword']);
			$idWpRestrictedKeyword = RestrictedKeywordDAL::Save($objRestrictedKeyword);
		}

		$arrayObjRestrictedKeyword = RestrictedKeywordDAL::GetArrayObj(null);
		$this->smarty->assign('arrayObjRestrictedKeyword', $arrayObjRestrictedKeyword);

	}


	/**
	 * Edycja RestrictedKeyword
	 *
	 * @param array $param
	 */
	public function EditAction($param) {

		if(isset($param['id'])) {
			$id = $param['id'];
		} 
		else {
			$id = null;
		}

		$objRestrictedKeyword = RestrictedKeywordDAL::GetObjRestrictedKeyword($id);
		$this->smarty->assign('objRestrictedKeyword', $objRestrictedKeyword);
	}

	/**
	 * Usuwanie RestrictedKeyword
	 *
	 * @param array $param
	 */
	public function DeleteAction($param) {
			
		if(isset($param['id'])) {
			$id = $param['id'];
		} 
		else {
			$id = null;
		}
			
		RestrictedKeywordDAL::Delete($id);
		die(header("Location: restrictedkeyword".APPLICATION_FILE_TYPE));			
	}
	
	/**
	 * Dodaj RestrictedKeyword
	 *
	 */
	public function AddAction() {
		
		$this->partialTemplate = 'Edit.tpl';
		$objRestrictedKeyword = RestrictedKeywordDAL::GetObjRestrictedKeyword(-1);		
		$this->smarty->assign('objRestrictedKeyword', $objRestrictedKeyword);
	}

	/**
	 * Metoda wspolna
	 *
	 */
	public function preDispatch() {
		$this->RunShared('Auth');
			
		$admin = AuthDAL::GetAdmin();
		if(!$admin->CheckAccess('moderator')) {
			die(Header("Location: index".APPLICATION_FILE_TYPE));
		}
	}
}
